/*
 * Copyright 2007-2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.ymate.platform.commons.serialize.fst;

import net.ymate.platform.commons.util.ClassUtils;
import net.ymate.platform.commons.util.RuntimeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nustaq.serialization.FSTConfiguration;

/**
 * @author 刘镇 (suninformation@163.com) on 2022/9/27 13:24
 * @since 2.1.2
 */
public class FstConfigurationFactory implements IFstConfigurationFactory {

    private static final Log LOG = LogFactory.getLog(FstConfigurationFactory.class);

    private static IFstConfigurationFactory instance;

    static {
        try {
            IFstConfigurationFactory factory = ClassUtils.getExtensionLoader(IFstConfigurationFactory.class).getExtension();
            if (factory == null) {
                factory = new FstConfigurationFactory();
            }
            instance = factory;
        } catch (Exception e) {
            if (LOG.isWarnEnabled()) {
                LOG.warn(StringUtils.EMPTY, RuntimeUtils.unwrapThrow(e));
            }
        }
    }

    public static IFstConfigurationFactory getInstance() {
        return instance;
    }

    private final FSTConfiguration fstConfiguration = FSTConfiguration.createDefaultConfiguration();

    @Override
    public FSTConfiguration getFstConfiguration() {
        return fstConfiguration;
    }
}
